import sqlite3

# 连接到SQLite数据库
conn = sqlite3.connect('test.db')

# 创建一个Cursor对象
cursor = conn.cursor()

# 创建表
cursor.execute('''CREATE TABLE IF NOT EXISTS users
                 (id INTEGER PRIMARY KEY AUTOINCREMENT,
                 name TEXT,
                 age INTEGER)''')

print("Table created successfully")
# 插入数据
cursor.execute("INSERT INTO users (name, age) VALUES (?,?)", ('Alice', 25))
cursor.execute("INSERT INTO users (name, age) VALUES (?,?)", ('Bob', 30))
cursor.execute("INSERT INTO users (name, age) VALUES (?,?)", ('Charlie', 35))

# 提交事务
conn.commit()
print("Records created successfully")
# 查询数据
cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
for row in rows:
    print(row)

# 关闭Cursor和Connection
cursor.close()
conn.close()    